<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RabbitMQ 路由键与绑定键深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            bottom: -50%;
            left: -50%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 1px, transparent 1px);
            background-size: 50px 50px;
            animation: drift 20s linear infinite;
        }
        
        @keyframes drift {
            from { transform: translate(0, 0); }
            to { transform: translate(50px, 50px); }
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(to bottom, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        .key-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 500;
            display: inline-block;
            margin: 0 4px;
            transition: all 0.3s ease;
        }
        
        .key-badge:hover {
            transform: scale(1.05);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        
        .info-box {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 20px;
            border-radius: 8px;
            margin: 20px 0;
            transition: all 0.3s ease;
        }
        
        .info-box:hover {
            transform: translateX(5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 24px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            border-top: 3px solid transparent;
            border-image: linear-gradient(to right, #667eea, #764ba2) 1;
        }
        
        .feature-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        }
        
        .mermaid {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .highlight-text {
            background: linear-gradient(to right, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
        
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 relative">
        <div class="container mx-auto px-6 relative z-10">
            <div class="text-center">
                <i class="fas fa-network-wired text-6xl mb-6 floating-icon"></i>
                <h1 class="text-5xl font-bold mb-4">RabbitMQ 路由键与绑定键</h1>
                <p class="text-xl opacity-90 max-w-3xl mx-auto">深入理解消息队列中的核心概念，掌握高效路由设计的精髓</p>
                <div class="mt-8 flex justify-center space-x-4">
                    <span class="key-badge"><i class="fas fa-key mr-2"></i>Routing Key</span>
                    <span class="key-badge"><i class="fas fa-link mr-2"></i>Binding Key</span>
                    <span class="key-badge"><i class="fas fa-ruler mr-2"></i>255 字节限制</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- 核心概念介绍 -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">核心概念解析</h2>
            
            <div class="grid md:grid-cols-2 gap-6 mt-8">
                <div class="feature-card">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-paper-plane text-3xl text-purple-600 mr-4"></i>
                        <h3 class="text-xl font-bold">Routing Key <span class="text-gray-500 text-sm font-normal">路由键</span></h3>
                    </div>
                    <p class="text-gray-700 leading-relaxed">
                        消息发布时指定的键，用于指示交换机如何将消息路由到队列。生产者在发送消息时提供 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">routing key</code>，交换机根据这个键决定消息的去向。
                    </p>
                    <div class="mt-4 p-4 bg-purple-50 rounded-lg">
                        <p class="text-sm text-purple-700"><i class="fas fa-info-circle mr-2"></i>关键作用：消息路由的"地址"</p>
                    </div>
                </div>
                
                <div class="feature-card">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-link text-3xl text-indigo-600 mr-4"></i>
                        <h3 class="text-xl font-bold">Binding Key <span class="text-gray-500 text-sm font-normal">绑定键</span></h3>
                    </div>
                    <p class="text-gray-700 leading-relaxed">
                        队列和交换机之间创建绑定时使用的键。它定义了交换机如何将消息路由到队列。通过 <code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">binding key</code> 建立路由规则。
                    </p>
                    <div class="mt-4 p-4 bg-indigo-50 rounded-lg">
                        <p class="text-sm text-indigo-700"><i class="fas fa-info-circle mr-2"></i>关键作用：路由规则的"模板"</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- 长度限制详解 -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">长度限制详解</h2>
            
            <div class="info-box">
                <h4 class="text-lg font-bold mb-2 flex items-center">
                    <i class="fas fa-exclamation-triangle text-yellow-600 mr-3"></i>
                    重要限制
                </h4>
                <p class="text-gray-700">
                    RabbitMQ 对 <span class="key-badge">routing key</span> 和 <span class="key-badge">binding key</span> 的最大长度限制均为 <span class="highlight-text text-2xl">255 字节</span>。这一限制源于 AMQP 协议的设计规范。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-6 mt-8">
                <div class="bg-gradient-to-br from-purple-50 to-indigo-50 p-6 rounded-xl">
                    <h4 class="text-lg font-bold mb-3 flex items-center">
                        <i class="fas fa-ruler-horizontal text-purple-600 mr-3"></i>
                        字节计算注意事项
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-check text-green-500 mr-2"></i>UTF-8 编码中，中文字符通常占用 3 个字节</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>ASCII 字符占用 1 个字节</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>特殊符号可能占用 2-4 个字节</li>
                    </ul>
                </div>
                
                <div class="bg-gradient-to-br from-indigo-50 to-purple-50 p-6 rounded-xl">
                    <h4 class="text-lg font-bold mb-3 flex items-center">
                        <i class="fas fa-tachometer-alt text-indigo-600 mr-3"></i>
                        性能影响
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-bolt text-yellow-500 mr-2"></i>过长的键会降低路由效率</li>
                        <li><i class="fas fa-database text-blue-500 mr-2"></i>增加存储开销</li>
                        <li><i class="fas fa-network-wired text-purple-500 mr-2"></i>影响网络传输性能</li>
                    </ul>
                </div>
            </div>
        </div>

        <!-- 可视化图表 -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">消息路由流程图</h2>
            <div class="mermaid">
                graph LR
                    A[生产者] -->|routing key| B[交换机]
                    B -->|匹配 binding key| C[队列1]
                    B -->|匹配 binding key| D[队列2]
                    B -->|匹配 binding key| E[队列3]
                    C --> F[消费者1]
                    D --> G[消费者2]
                    E --> H[消费者3]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#f093fb,stroke:#333,stroke-width:2px
                    style D fill:#f093fb,stroke:#333,stroke-width:2px
                    style E fill:#f093fb,stroke:#333,stroke-width:2px
                    style F fill:#4facfe,stroke:#333,stroke-width:2px
                    style G fill:#4facfe,stroke:#333,stroke-width:2px
                    style H fill:#4facfe,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- 最佳实践 -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">设计最佳实践</h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white p-6 rounded-xl shadow-lg hover:shadow-xl transition-all">
                    <div class="text-center mb-4">
                        <i class="fas fa-lightbulb text-4xl text-yellow-500"></i>
                    </div>
                    <h4 class="text-lg font-bold mb-3 text-center">合理设计</h4>
                    <p class="text-gray-600 text-sm">
                        保持键名简短且语义明确，避免冗余信息。使用点号分隔的层级结构，如 <code class="bg-gray-100 px-2 py-1 rounded text-xs">order.created.china</code>
                    </p>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-lg hover:shadow-xl transition-all">
                    <div class="text-center mb-4">
                        <i class="fas fa-puzzle-piece text-4